/**
 *model 
 */    
    Ext.define('model_yp', {
         extend: 'Ext.data.Model',
         fields: [
                {name: 'yp_dm', type: 'string'},
                {name: 'yp_mc', type: 'string'},
                {name: 'yp_hs', type: 'string'}
         ]
     });
/**
 *store 
 */     
     var store_yp=Ext.create('Ext.data.Store', {
        model: 'model_yp',
        autoDestroy: true,
        autoLoad: true,
        pageSize:100,
        proxy: {
            type: 'ajax',
            url: 'getOilsListAction.action',
            reader: {
                type: 'json',
                root: 'items',
                totalProperty:'totalCount'
            }
        }
     });

 /**
  *grid表格头 
  */    
     var col_yp=[
        {xtype:'rownumberer'}, 
        {dataIndex:'yp_dm',text:'油品代码',width:100,menuDisabled:true,sortable:false},
        {dataIndex:'yp_mc',text:'油品名称',width:100,menuDisabled:true,sortable:false},
        {dataIndex:'yp_hs',text:'计量系数',width:100,menuDisabled:true,sortable:false}
     ];

     Ext.onReady(function(){
         Ext.create('Ext.panel.Panel',{
             id:'main-panel',
             width:Ext.getBody().getWidth()-20,
             renderTo:Ext.getBody(),
             layout:{
                 type:'vbox',
                 align: 'stretch'
             },
             items:[{
                        xtype: 'grid',
                        id:'grid_yp',
                        title:'油品信息表',
                        height:650,
                        //selModel: Ext.create('Ext.selection.CheckboxModel', { mode: "SIMPLE" }),
                        columns: col_yp,            
                        store: store_yp,
/*                        features: [{
                            groupHeaderTpl: '{name}',
                            ftype: 'summary'
                        }],*/
                        dockedItems:[
                            {
                                xtype: 'toolbar',
                                items:[{
                                    xtype:'button',
                                    text:'新增',
                                    margin:'10 10 0 10',
                                    width:100,
                                    handler:showDlgOilsAdd
                                },{
                                    xtype:'button',
                                    text:'修改',
                                    margin:'10 10 0 10',
                                    width:100,
                                    handler:function(){
                                        var g=Ext.getCmp('grid_yp');
                                        var m=g.getSelectionModel().getSelection();
                                        if (m.length>0) {
                                            showDlgOilsModif(m[0].raw);
                                        }else{
                                            Ext.Msg.alert('提示信息','请选中要修改的油品！');
                                        };
                                        
                                    }
                                },{
                                    xtype:'button',
                                    text:'删除',
                                    margin:'10 10 0 10',
                                    width:100,
                                    handler:function(){
                                        var g=Ext.getCmp('grid_yp');
                                        var m=g.getSelectionModel().getSelection();
                                        if (m.length>0) {
                                            showDlgOilsDel(m[0].raw);
                                        }else{
                                            Ext.Msg.alert('提示信息','请选中要删除的油品！');
                                        };
                                    }
                                }]
                            },{
                                xtype: 'pagingtoolbar',
                                store: store_yp,   
                                dock: 'bottom',
                                displayInfo: true
                            }
                        ], 
                        flex: 1  
             }]
         });
     });

     function showDlgOilsAdd(){
         var dlg=Ext.create('Ext.window.Window',{
             title:'新增油品信息',
             width:350,
             height:250,
             layout:'fit',
             resize:false,
             modal:true,
             items:[
                    Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        //width:700,
                        layout:'anchor',
                        items:[
                            {
                                xtype:'textfield',
                                fieldLabel:'油品代码',
                                name: 'yp_dm',
                                allowBlank:false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'油品名称',
                                name: 'yp_mc',
                                allowBlank:false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'numberfield',
                                fieldLabel:'计量系数',
                                name: 'yp_hs',
                                allowBlank:false,
                                labelWidth:80,
                                width:300
                            }
                     ],
                     buttons:[{
                            text:'提交',
                            handler:function(){
                                    var f=this.up('form').getForm();
                                    if (f.isValid()) {
                                        f.submit({
                                            url:'addOilsAction.action',
                                            clientValidation:false,
                                            waitMsg:'正在提交数据,请稍候...',
                                            success: function(form, action){
                                                Ext.Msg.alert('提示信息',action.result.msg); 
                                                store_yp.loadPage(1);
                                                dlg.close();
                                            },
                                            failure: function(form, action) {
                                                Ext.Msg.alert('提示信息',action.result.msg); 
                                            }
                                        });
                                    };
                                    //dlg.close();
                            }
                        },{
                            text:'重置',handler:function(){this.up('form').getForm().reset();}
                        },{
                            text:'关闭',handler:function(){dlg.close();}
                    }]
                })
             ]
         });
         dlg.show();
     }
     /**
      * 
      */
          function showDlgOilsModif(raw){
             var dlg=Ext.create('Ext.window.Window',{
                 title:'修改油品信息',
                 width:350,
                 height:250,
                 layout:'fit',
                 resize:false,
                 modal:true,
                 items:[
                        Ext.create('Ext.form.Panel',{
                            bodyPadding:5,
                            //width:700,
                            layout:'anchor',
                            items:[
                                {
                                    xtype:'textfield',
                                    fieldLabel:'油品代码',
                                    name: 'yp_dm',
                                    readOnly:true,
                                    value:raw.yp_dm,
                                    allowBlank:false,
                                    labelWidth:80,
                                    width:300
                                },{
                                    xtype:'textfield',
                                    fieldLabel:'油品名称',
                                    name: 'yp_mc',
                                    value:raw.yp_mc,
                                    allowBlank:false,
                                    labelWidth:80,
                                    width:300
                                },{
                                    xtype:'numberfield',
                                    fieldLabel:'计量系数',
                                    name: 'yp_hs',
                                    value:raw.yp_hs,
                                    allowBlank:false,
                                    labelWidth:80,
                                    width:300
                                }
                         ],
                         buttons:[{
                                text:'提交',
                                handler:function(){
                                        var f=this.up('form').getForm();
                                        if (f.isValid()) {
                                            f.submit({
                                                url:'modifOilsAction.action',
                                                clientValidation:false,
                                                waitMsg:'正在提交数据,请稍候...',
                                                success: function(form, action){
                                                    Ext.Msg.alert('提示信息',action.result.msg); 
                                                    store_yp.loadPage(1);
                                                    dlg.close();
                                                },
                                                failure: function(form, action) {
                                                    Ext.Msg.alert('提示信息',action.result.msg); 
                                                }
                                            });
                                        };
                                        //dlg.close();
                                }
                            },{
                                text:'重置',handler:function(){this.up('form').getForm().reset();}
                            },{
                                text:'关闭',handler:function(){dlg.close();}
                        }]
                    })
                 ]
             });
             dlg.show();
         }
          function showDlgOilsDel(raw){
             var dlg=Ext.create('Ext.window.Window',{
                 title:'删除油品信息',
                 width:350,
                 height:250,
                 layout:'fit',
                 resize:false,
                 modal:true,
                 items:[
                        Ext.create('Ext.form.Panel',{
                            bodyPadding:5,
                            //width:700,
                            layout:'anchor',
                            items:[
                                {
                                    xtype:'textfield',
                                    fieldLabel:'油品代码',
                                    name: 'yp_dm',
                                    readOnly:true,
                                    value:raw.yp_dm,
                                    allowBlank:false,
                                    labelWidth:80,
                                    width:300
                                },{
                                    xtype:'textfield',
                                    fieldLabel:'油品名称',
                                    name: 'yp_mc',
                                    readOnly:true,
                                    value:raw.yp_mc,
                                    allowBlank:false,
                                    labelWidth:80,
                                    width:300
                                },{
                                    xtype:'numberfield',
                                    fieldLabel:'计量系数',
                                    name: 'yp_hs',
                                    readOnly:true,
                                    value:raw.yp_hs,
                                    allowBlank:false,
                                    labelWidth:80,
                                    width:300
                                }
                         ],
                         buttons:[{
                                text:'删除',
                                handler:function(){
                                        var f=this.up('form').getForm();
                                        if (f.isValid()) {
                                            f.submit({
                                                url:'delOilsAction.action',
                                                clientValidation:false,
                                                waitMsg:'正在提交数据,请稍候...',
                                                success: function(form, action){
                                                    Ext.Msg.alert('提示信息',action.result.msg); 
                                                    store_yp.loadPage(1);
                                                    dlg.close();
                                                },
                                                failure: function(form, action) {
                                                    Ext.Msg.alert('提示信息',action.result.msg); 
                                                }
                                            });
                                        };
                                        //dlg.close();
                                }
                            },{
                                text:'关闭',handler:function(){dlg.close();}
                        }]
                    })
                 ]
             });
             dlg.show();
         }